package com.my12306.train.controller;

import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.model.entity.ZoneEntity;
import com.my12306.train.service.ZoneService;
import com.my12306.train.model.vo.ZoneVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ËÕÄÁÏ¦
 */
@RestController
@RequestMapping("/zone")
public class ZoneController {
    @Autowired
    private ZoneService zoneService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public ResponseData list(ZoneVO zoneVO, @RequestParam(defaultValue = "1") long page, @RequestParam(defaultValue = "5")long size) {
        PageUtils page1 = zoneService.find(zoneVO, page, size);

        return ResponseData.ok().put("page", page1);
    }
    /**
     * 列表
     */
    @PostMapping("/lst")
    public ResponseData list(@RequestBody PageVo pageVo) {
        PageUtils page1 = zoneService.queryZoneByPage(pageVo);
        return ResponseData.ok().put("page", page1);
    }

    /**
     * 信息
     */
    @GetMapping("/inf/{id}")
    public ResponseData info(@PathVariable("id") Long id) {
        ZoneEntity zone = zoneService.queryZoneById(id);
        return ResponseData.ok().put("zone", zone);
    }


    /**
     * 保存
     */
    @PostMapping("/sv")
    public ResponseData save(@RequestBody ZoneEntity zone) {
        zoneService.saveZone(zone);
        return ResponseData.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/up")
    public ResponseData update(@RequestBody ZoneEntity zone) {
        zoneService.updateZoneById(zone);
        return ResponseData.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/del")
    public ResponseData delete(@RequestBody List<Long> ids) {
        zoneService.removeZoneByIds(ids);

        return ResponseData.ok();
    }

}
